export class Person {
  private _name: string;
  private _age: number;

  constructor(name: string, age: number) {
    this._name = name;
    this._age = age;
  }

  private privateMethod(): void {
    console.log("这是一个私有方法");
  }

  sayHello() {
    console.log("Hello");
  }

  get name() {
    return this._name;
  }

  set name(value) {
    // 之所以要设置 getter/setter 是因为我们可以在这里做一些额外的操作
    // 比如对 value 做一些校验
    this._name = value;
  }

  get age() {
    return this._age;
  }

  set age(value) {
    if (value > 100) {
      console.log("年龄不能大于100");
      this._age = 20;
    } else {
      this._age = value;
    }
  }
}

const p = new Person("John", 18);
console.log(p.name);
p.age = 200;
console.log(p.age);
